<template>
  <div class="analysisContainer">
   <div class="title">题目：{{stem.name}}</div>

     <div class="optionList">
       <radio-group class="radioGroup" v-if="stem">
         <label
           class="radio"
           style="display: block;"
           v-for="(item,index) in stem.optionList"
           :key="item.id"
         >
           <radio color="#2e8e9a" :value="item.content" :check="false"/>
           <span>{{item.content}}</span>
         </label>
       </radio-group>
     </div>

   <div>你的答案：{{stem.optionList[choseIndex].content}}</div>
   <div>正确答案：{{stem.optionList[rightIndex].content}}</div>

   <view class="container">
        <!-- 分割线 -->
     <view class="divLine"></view>
   </view>
   <div>解析:{{stem.analysis}}</div>

   <view class="container">
        <!-- 分割线 -->
     <view class="divLine"></view>
   </view>
   <div class="buttonContainer" style="text-align:center;">
   <button class="weui-btn weui-btn_mini weui-btn_default" @click="addWrong">加入错题集</button>
   </div>
  </div>
</template>

<script>
import HttpKit from '@/utils/http-kit'
import globalStore from "../../stores/global-store";
const EXAM_LIST_URL = 'http://127.0.0.1:8080/base-in-back-end'

export default {
  data () {
    return {
      stem: {}, //题目
      choseIndex: 0, //该题选择的下标
      rightIndex: 0, //该题正确答案下标
    }
  },

  onLoad: function (option) {
      this.stem = globalStore.state.examingStem[option.choseStemIndex];
      this.choseIndex = option.choseIndex;

      for(let i=0; i<this.stem.optionList.length;i++){
        if(this.stem.optionList[i].isRight){
          console.log(this.stem.optionList[i].isRight);
          this.rightIndex=i;
        }
      }
      console.log(this.rightIndex);
      console.log(this.stem)
      console.log(this.choseIndex)
  },

  onUnload: function () {

  },


  methods: {
    addWrong(){
      var tid = this.stem.id;
      console.log(tid);
      this.$fly.post(EXAM_LIST_URL + '/common/wrong/add/' + globalStore.state.openId + '/' + tid)
      .then(e => {
        console.log(e)
        wx.showToast({
          title:'成功',
          icon:'none',
          duration:2000
        })
      })
      .catch(err => {
      })
    }
  }
}

</script>

<style scoped >
.divLine{
 background: #E0E3DA;
 width: 100%;
 height: 5rpx;
}
.title {
  margin-top: 30px;
  margin-bottom: 15px;
}
.analysisContainer{
  display: flex;
  flex-direction: column;
  align-items: center;
  width: 80%;
  height: 100%;
  margin: 0 auto;
}
.optionList {
  margin: 0 auto 10px;
}
.buttonContainer {
  margin-top: 20px;
}
</style>
